<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <link href="static/bootstrap-3.4.1-dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="static/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>
  <script src="static/js/jquery.min.js"></script>
  <title>登录页面</title>
</head>
<body>
<div style="width:50%;height:50%;position:absolute;top:25%;left:35%;">
  <form class="form-horizontal" id="myForm">
    <!--    <form class="form-horizontal" action="/week10_war/successToJsp.jsp" method="get">-->
    <div class="form-group">
      <label  class="col-sm-2 control-label">用户名:</label>
      <div style="width:40%" class="col-sm-10">
        <input  class="form-control" name="username"  placeholder="用户名">
      </div>
    </div>
    <div class="form-group">
      <label for="inputPassword3" class="col-sm-2 control-label">密码:</label>
      <div style="width:40%" class="col-sm-10">
        <input type="password" class="form-control" name="password" id="inputPassword3" placeholder="Password">
      </div>
      <p id="errorTip" style="text-align: center;font-size: 18px;color: red"></p>
    </div>
    <div class="form-group">
      <div class="col-sm-offset-2 col-sm-10">
        <div class="checkbox">
          <label>
            <input type="checkbox">记住我
          </label>
        </div>
      </div>
    </div>
    <div class="form-group">
      <div class="col-sm-offset-2 col-sm-10">
        <input id="btnSubmit"  class="btn btn-info" value="登 录"></input>
      </div>
    </div>
  </form>
</div>
<div id="errorTips" style="text-align: center;font-size: 18px;color: red"></div>
</body>
</html>
<script>
  $(function() {
    var $password = $('input[name=password]');
    var $errorTip = $('#errorTip');

    // 鼠标离开密码输入框时的事件处理
    $password.on('mouseleave', function() {
      var passwordValue = $password.val();
      if (passwordValue.length > 6) {
        $errorTip.text("密码安全性很高");
        $errorTip.css('color', 'green');
      } else if (passwordValue.length < 6) {
        $errorTip.text("密码小于六位，安全性很弱");
        $errorTip.css('color', 'red');
      } else {
        $errorTip.text("");
      }
    });
    //密码安全性校验
    // $('#inputPassword3').mouseleave(function() {
    //         //使用 $.ajax-get 发送请求
    //         Jquery_AJAX_GET_pwd();
    // });
    //使用 $.ajax()   方法发送请求
    function Jquery_AJAX_GET_demo() {
      $.ajax({
        type: "get",
        contentType: "application/json",
        url: 'http://localhost:8080/registerAjax.do',
        dataType: "json",
        data: {
          username: $('input[name=username]').val(),
          password: $('input[name=password]').val()
        },
        async: "true",
        success: function (result) {
          if (result.status == 'error') {
            $('#errorTips').text("密码长度小于6安全性低!");
            //console.log(result.status)
          } else if (result.status == 'success') {
            $('#errorTips').text("密码安全性高");
          }
        },
        error: function (e) {
          alert("error")
        }
      })
    }
    //使用 $.ajax() 的 post 方法 发送请求
    function Jquery_AJAX_POST_demo() {
      $.ajax({
        type: "post",
        contentType: "application/x-www-form-urlencoded",
        url: 'http://localhost:8080/registerAjax.do',
        dataType: "json",
        data: $('#myForm').serialize(),
        success: function(result) {
          if(result.status == 'error') {
            $('#errorTips').text("密码错误!");
          } else if(result.status == 'success') {
            window.location.href = "http://localhost:8080/success.html";
          }
        },
        error: function(e) {
          alert("error")
        }
      })
    }


    function Jquery_AJAX_GET_pwd() {
      $.ajax({
        type: "get",
        contentType: "application/json",
        url: 'http://localhost:8080/registerAjax.do',
        dataType: "json",
        data: {
          password: $('input[name=password]').val()
        },
        async: "true",
        success: function (result) {
          if (result.status == 'error') {
            $('#errorTip').text("密码长度过低，安全性低!");
            //console.log(result.status)
          } else if (result.status == 'success') {
            $('#errorTip').text("密码安全性很高!");
          }
        },
        error: function (e) {
          alert("error")
        }
      })
    }
  })
</script>